define(function(require) {
	
	var $ = require("jquery1.7");
	
	var backManagerService = require("bean/backManagerService");
	var utils = require("utils");
	var ctx = utils.constants.ctx;
	var ui = require("ui");
	
	var table = layui.table;
	var layer = layui.layer;
	var tablelin = table.render({
	    elem: '#demo'
	    ,url : '/back/base/userAuditData'
	    ,cols: [[ //标题栏
	      {checkbox: true}
	      ,{field: 'username', title: '用户名', width: 180}
	      ,{field: 'nickname', title: '用户昵称', width: 180}
	      ,{field: 'createTime', title: '创建时间', width: 220}
	      ,{field: '', title: '操作', templet:'#table_ope', width: 100}
	    ]] 
	    ,even: true
	    ,page: true //是否显示分页
	    ,limits: [8, 12, 15,18]
	    ,limit: 15 //每页默认显示的数量
	    ,id: "auditTable"
	  });
	
	//时间插件初始化
	var laydate = layui.laydate;
	  
	  //执行一个laydate实例
	  laydate.render({
	    elem: '#dateRange' //指定元素
	    ,range: true
	  });
	
	//重载表格事件
	$(document).on("click","#searchBtn",function(){
		tablelin.reload({
			where:{
				username:$("#search_input").val()
			}
		});
	})
	$(document).on("click","#userApproved",function(){
		layer.confirm("是否通过审核?",{icon: 3, title:'提示'},function(){
			var userId = $("#user_id").val();
			if(userId == null){
				return  false ;
			}
			try {
				ui.mask().show("请稍候...");
				backManagerService.userApproval(userId);
				ui.mask().hide();
				layer.alert("审核成功",function(){
					
					location.href = ctx+"/back/base/userAuditList";
				});
			} catch(e){
				ui.mask().hide();
				layer.alert("审核失败");
			}
		});
	});
	
	$("#userUnApproved").bind("click",function(){
		layer.confirm("是否不通过审核?",{icon: 3, title:'提示'},function(){
			var userId = $("#user_id").val();
			if(userId == null){
				return  false ;
			}
			try {
				ui.mask().show("请稍候...");
				backManagerService.userUnApproval(userId);
				ui.mask().hide();
				layer.alert("操作成功",function(){
					
					location.href = ctx+"/back/base/userAuditList";
				});
			} catch(e){
				ui.mask().hide();
				layer.alert("审核失败");
			}

		});
	});
	
	var layer = layui.layer;
	$("#auditUserList").bind("click",function(){
		
		var checkStatus = table.checkStatus('auditTable');
		if(checkStatus.data.length==0){
			layer.msg("请选择用户！")
			return;
		}
		layer.confirm("确定这些用户通过审核?",function(){
			var data = checkStatus.data;
			var array = [];
			for(var i = 0; i<data.length;i++){
				array.push(data[i].id);   
			}
			if (array.length != 0) {
				try{
					var a = showShade();
					backManagerService.userApprovalList(array);
					layer.close(a)
					layer.msg("审核成功");
					tablelin.reload();
				} catch (e) {
					layer.close(a)
					layer.alert("审核失败:"+e.message);
				}
			} 
			
		})
		
	});
	
	
	//取消审核
	$(document).on("click","#cancel",function(){
		location.href = ctx + "/back/base/userAuditList";
	});
	
	//用户审批详细
	$(document).on("click",".w_btn_href",function(){
		var userId=$(this).attr("data");
		location.href = ctx + "/back/base/userdetail?userId=" + userId;
	});
	
});